<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.cqggrw.util.*"%>
<%
	String commond = request.getParameter("commond");
	if ("del".equals(commond)) {
		String id = request.getParameter("id");
		if (id != null) {
			System.out.println(id);
			Connection conn = null;
			PreparedStatement ps = null;
			ResultSet rs = null;

			String sql = "delete from tbl_category where id = ?;";
			int i = 0;
			try {
				conn = DBUtil.getConn();
				ps = conn.prepareStatement(sql);
				ps.setInt(1, Integer.parseInt(id));
				i = ps.executeUpdate();
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				DBUtil.close(conn, ps, rs);
			}
		}
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>公共人物网后台管理</title>
<link type="text/css" rel="Stylesheet" href="../Content/Index.css" />
<script type="text/javascript" src="../../jslib/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {

		$("#dgvCategoryList").find("tr").slice(1).each(function(i) {
			var cateId = $(this).attr("cateId");
			var ParentID = $(this).attr("ParentID");
			if (ParentID.length == 0) {
				var img = "<img src='../Content/Images/menu_plus.gif' onclick='toggleChildrenRow(this)' style='cursor:hand'></img>";
				var cateNameDom = $(this).children(":first").children();
				$(img).insertBefore($(cateNameDom));
			} else {
				$(this).css("display", "none");
			}
		});
	});
	function toggleChildrenRow(imgDom) {
		var currentRow = $(imgDom).parent().parent();
		var cateId = currentRow.attr("cateId");
		var imgSrc = $(imgDom).attr("src");
		var visibly;
		if (imgSrc.indexOf("menu_plus.gif") > 0) {
			visibly = true;
			$(imgDom).attr("src", "../Content/Images/menu_minus.gif");
		} else {
			visibly = false;
			$(imgDom).attr("src", "../Content/Images/menu_plus.gif");
		}
		$("#dgvCategoryList").find("tr[ParentID='" + cateId + "']").each(function(i) {
			if (visibly == true) {
				$(this).show("fast");
			} else {
				$(this).hide("fast");
			}
		});
	}
	
	function del(id) {
		if (confirm("您是否要删除该信息？")) {
			location.href ="CategoryList.jsp?commond=del&id="+id;
		}
	}
</script>
<style type="text/css">
img {
	border: 0px;
}
</style>
</head>
<body>
	<form name="form1" method="post" action="CategoryList.aspx" id="form1">
		<div class="form-div textLeft">
			<h1>
				<span class="action-span"><a href="CategoryEdit.jsp">添加分类</a> </span> <span class="action-span1 fs20">公共人物网 管理中心 </span><span class="action-span1 paddingTop5"> - 信息分类 </span>
			</h1>
			<div style="clear:both"></div>
		</div>
		<div>
			<div>
				<table class="customeGridView" cellspacing="0" rules="all" border="1" id="dgvCategoryList" style="width:100%;border-collapse:collapse;">
					<tr>
						<th scope="col"><span id="dgvCategoryList_ctl01_lblTitleNumber">ID</span>
						</th>
						<th scope="col"><span id="dgvCategoryList_ctl01_lblTitleNumber">分类名称</span>
						</th>
						<th scope="col"><span id="dgvCategoryList_ctl01_lblTitleOperate">操作列表</span>
						</th>
					</tr>
					<%
						Connection conn = null;
						PreparedStatement ps = null;
						ResultSet rs = null;

						String sql = "SELECT * FROM tbl_category;";
						try {
							conn = DBUtil.getConn();
							ps = conn.prepareStatement(sql);
							rs = ps.executeQuery();

							while (rs.next()) {
					%>
					<tr cateId="<%=rs.getInt("id")%>" ParentID="">
						<td align="left" style="width:120px;"><span id="dgvCategoryList_ctl02_lblCategoryName"><%=rs.getInt("id")%></span>
						</td>
						<td align="left" style="width:120px;"><span id="dgvCategoryList_ctl02_lblCategoryName"><%=rs.getString("name")%></span>
						</td>
						<td style="width:60px;"><a href='CategoryEdit.jsp?commond=modify&id=<%=rs.getInt("id")%>'><img alt="修改" src="../Content/Images/icon_edit.gif" /> </a> <a href="javascript:void(0)" onclick="del(<%=rs.getInt("id")%>)"><img alt="删除" src="../Content/Images/icon_trash.gif" /> </a> <input id="Hidden1" type="hidden" value='38' />
						</td>
					</tr>
					<%
						}
						} catch (Exception e) {
							e.printStackTrace();
						} finally {
							DBUtil.close(conn, ps, rs);
						}
					%>
				</table>
			</div>
		</div>
	</form>
</body>
</html>